package com.jinmei.mail.request;

import com.jinmei.mail.oauth.OAuth;
import com.jinmei.remote.request.BaseClientRequest;
import com.jinmei.remote.request.RequestBuilder;

/**
 * @author richard
 *
 */
public class ExmailClientRequest extends BaseClientRequest {

    protected ExmailClientRequest(String url) {
    	super(url);
    }
    
	public static TokenRequestBuilder tokenLocation(String url) {
        return new TokenRequestBuilder(url);
    }
	
	public static ListeningRequestBuilder listeningLocation(String url) {
        return new ListeningRequestBuilder(url);
    }
	
	public static PullClientRequestBuilder pullLocation(String url) {
        return new PullClientRequestBuilder(url);
    }

	public static class ListeningRequestBuilder extends ExmailRequestBuilder {
		public ListeningRequestBuilder(String url) {
			super(url);
        }
		
        public ListeningRequestBuilder setAccessToken(String accessToekn) {
            this.parameters.put(OAuth.OAUTH_ACCESS_TOKEN, accessToekn);
            return this;
        }

        public ListeningRequestBuilder setClientVersion(String version) {
            this.parameters.put(OAuth.VERSION, version);
            return this;
        }
        
        public ListeningRequestBuilder setParameter(String paramName, String paramValue) {
            this.parameters.put(paramName, paramValue);
            return this;
        }

	}
	
	public static class TokenRequestBuilder extends ExmailRequestBuilder {
        public TokenRequestBuilder(String url) {
            super(url);
        }

        public TokenRequestBuilder setGrantType(String grantType) {
            this.parameters.put(OAuth.OAUTH_GRANT_TYPE, grantType);
            return this;
        }

        public TokenRequestBuilder setClientId(String clientId) {
            this.parameters.put(OAuth.OAUTH_CLIENT_ID, clientId);
            return this;
        }

        public TokenRequestBuilder setClientSecret(String secret) {
            this.parameters.put(OAuth.OAUTH_CLIENT_SECRET, secret);
            return this;
        }

        public TokenRequestBuilder setRedirectURI(String uri) {
            this.parameters.put(OAuth.OAUTH_REDIRECT_URI, uri);
            return this;
        }

        public TokenRequestBuilder setRefreshToken(String token) {
            this.parameters.put(OAuth.OAUTH_REFRESH_TOKEN, token);
            return this;
        }

        public TokenRequestBuilder setParameter(String paramName, String paramValue) {
            this.parameters.put(paramName, paramValue);
            return this;
        }
        
    }
	
	public static class PullClientRequestBuilder extends ExmailRequestBuilder {
		public PullClientRequestBuilder(String url) {
			super(url);
        }
		
        public PullClientRequestBuilder setAccessToken(String accessToekn) {
            this.parameters.put(OAuth.OAUTH_ACCESS_TOKEN, accessToekn);
            return this;
        }

        public PullClientRequestBuilder setAlias(String alias) {
            this.parameters.put(OAuth.ALIAS, alias);
            return this;
        }

        public PullClientRequestBuilder setParameter(String paramName, String paramValue) {
            this.parameters.put(paramName, paramValue);
            return this;
        }
        
	}

}
